package com.xuzimian.global.demo.spring.security.oauth2.resource.config;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 参考： https://www.liangzl.com/get-article-detail-27209.html
 * https://www.cnblogs.com/hetutu-5238/p/10022963.html    ------  https://github.com/hetutu5238/zmc_security_oauth2.git
 */
@Component
public class DenialAuthenticationEntryPoint implements AuthenticationEntryPoint {
    private final Logger logger = LoggerFactory.getLogger(DenialAuthenticationEntryPoint.class);

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        logger.info("拒绝访问！！！");
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied：拒绝访问！");
    }



}
